
package com.wake.widget.skin.handler;

import android.content.res.ColorStateList;
import android.view.View;
import android.widget.CompoundButton;
import android.widget.ImageView;

import com.wake.widget.skin.NMUISkinHelper;
import com.wake.widget.util.NMUIViewHelper;
import com.wake.widget.widget.NMUILoadingView;
import com.wake.widget.widget.pullRefreshLayout.NMUIPullRefreshLayout;

import androidx.core.widget.CompoundButtonCompat;
import androidx.core.widget.ImageViewCompat;

import org.jetbrains.annotations.NotNull;

public class NMUISkinRuleTintColorHandler extends NMUISkinRuleColorStateListHandler {

    @Override
    protected void handle(@NotNull View view, @NotNull String name, ColorStateList colorStateList) {
        if(colorStateList == null){
            return;
        }
        if(view instanceof NMUILoadingView){
            ((NMUILoadingView) view).setColor(colorStateList.getDefaultColor());
        }else if(view instanceof NMUIPullRefreshLayout.RefreshView){
            ((NMUIPullRefreshLayout.RefreshView)view).setColorSchemeColors(colorStateList.getDefaultColor());
        }else if (view instanceof ImageView) {
            ImageViewCompat.setImageTintList((ImageView) view, colorStateList);
        }else if(view instanceof CompoundButton){
            CompoundButtonCompat.setButtonTintList((CompoundButton)view, colorStateList);
        }else{
            NMUISkinHelper.warnRuleNotSupport(view, name);
        }
    }
}
